package com.bjbn.controller;

import com.bjbn.dto.PspLoginRequest;
import com.bjbn.dto.PspFlightDelayRequest;
import com.bjbn.dto.PspFlightDelayServiceRequest;
import com.bjbn.dto.PspLoginDataRequest;
import com.bjbn.dto.PspFlightDelayDataRequest;
import com.bjbn.dto.PspFlightDelayServiceDataRequest;
import com.bjbn.service.Webapi4PspService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;

import java.util.Map;

/**
 * 旅客服务平台API控制器
 *
 * @author bjbn
 */
@RestController
@RequestMapping("/CAN/PSP/passengerService/V1")
@Tag(name = "旅客服务平台API", description = "旅客服务平台相关接口")
public class PspController {

    @Autowired
    private Webapi4PspService webapiService;

    /**
     * 登录贵宾/航延系统
     *
     * @param request 登录请求
     * @return 响应结果
     */
    @PostMapping("/mps/rtr/api/action/login")
    @Operation(summary = "登录贵宾/航延系统", description = "必须登录成功后才能访问贵宾服务、航延服务系统")
    public Mono<ResponseEntity<Map<String, Object>>> pspLogin(@RequestBody PspLoginRequest request) {
        return webapiService.pspLogin(request)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 登录贵宾/航延系统（简化版）
     *
     * @param dataRequest 登录数据请求
     * @return 响应结果
     */
    @PostMapping("/mps/rtr/api/action/login/simple")
    @Operation(summary = "登录贵宾/航延系统（简化版）", description = "简化版登录接口，只需要传递system和password，header部分由系统自动生成")
    public Mono<ResponseEntity<Map<String, Object>>> pspLoginSimple(@RequestBody PspLoginDataRequest dataRequest) {
        return webapiService.pspLoginWithData(dataRequest)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 查询航延信息服务
     *
     * @param request 查询航延信息请求
     * @return 响应结果
     */
    @PostMapping("/pfp/dpsapi/action/queryKanbanData")
    @Operation(summary = "查询航延信息服务", description = "必须登录成功后才能访问航延服务，查询航延信息服务")
    public Mono<ResponseEntity<Map<String, Object>>> queryFlightDelayInfo(@RequestBody PspFlightDelayRequest request) {
        return webapiService.queryFlightDelayInfo(request)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 查询航延信息服务（简化版）
     *
     * @param dataRequest 查询航延信息数据请求
     * @return 响应结果
     */
    @PostMapping("/pfp/dpsapi/action/queryKanbanData/simple")
    @Operation(summary = "查询航延信息服务（简化版）", description = "简化版查询接口，只需要传递data部分，header部分由系统自动生成并自动处理登录")
    public Mono<ResponseEntity<Map<String, Object>>> queryFlightDelayInfoSimple(@RequestBody PspFlightDelayDataRequest dataRequest) {
        return webapiService.queryFlightDelayInfoWithData(dataRequest)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 查询航延服务信息服务
     *
     * @param request 查询航延服务信息请求
     * @return 响应结果
     */
    @PostMapping("/pfp/dpsapi/action/findKanbanData")
    @Operation(summary = "查询航延服务信息服务", description = "必须登录成功后才能访问航延服务，查询航延服务信息服务")
    public Mono<ResponseEntity<Map<String, Object>>> queryFlightDelayServiceInfo(@RequestBody PspFlightDelayServiceRequest request) {
        return webapiService.queryFlightDelayServiceInfo(request)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }

    /**
     * 查询航延服务信息服务（简化版）
     *
     * @param dataRequest 查询航延服务信息数据请求
     * @return 响应结果
     */
    @PostMapping("/pfp/dpsapi/action/findKanbanData/simple")
    @Operation(summary = "查询航延服务信息服务（简化版）", description = "简化版查询接口，只需要传递airport参数，header部分由系统自动生成并自动处理登录")
    public Mono<ResponseEntity<Map<String, Object>>> queryFlightDelayServiceInfoSimple(@RequestBody PspFlightDelayServiceDataRequest dataRequest) {
        return webapiService.queryFlightDelayServiceInfoWithData(dataRequest)
                .map(ResponseEntity::ok)
                .defaultIfEmpty(ResponseEntity.noContent().build());
    }
} 